<%@ page import="java.util.Date" %>
<%@ page import="javax.swing.text.DateFormatter" %>
<%@ page import="cs236369.hw5.DBConnection" %>
<%@ page import="cs236369.hw5.InitListener" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="cs236369.hw5.User" %>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body>
<%
	String name = (String)session.getAttribute("name");
	if(name == null) {
		response.sendRedirect(request.getContextPath() + InitListener.welcomePage);
		return;
	}
	String username = (String)session.getAttribute("userName");
	boolean isAdmin = session.getAttribute("admin") != null; // check if the user is an admon
	User user = DBConnection.getUserDetails(username);
%>
<p class="subtitle">Edit profile (<%= username %>)</p>
<form id="updateForm" onsubmit="return updateProfile();" action=""><p class="text">
	<label>First name:&nbsp;</label>
	<input type="text" name="firstName" value=<%= user.getFirstName() %> /><br />
	<label>Last name:&nbsp;</label>
	<input type="text" name="lastName" value=<%= user.getLastName() %> /><br />
	<label>Email:&nbsp;</label>
	<input type="email" name="email" value="<%= user.getEmail() %>" /><br />
	<label>Phone:&nbsp;</label>
	<input type="text" name="phone" value="<%= user.getPhone() %>" /><br /><br />
	<label>Password:&nbsp;</label>
	<input type="password" name="password" placeholder="Change password" /><br /><br />
	<%
		if(isAdmin == true) {
			out.println("<input type=\"checkbox\" name=\"adminCheck\" value=\"adminCheck\" checked />&nbsp");
			out.println("To remove yourself from admin, uncheck the box");
		} else {
			out.println("To become an admin, please type the admin password<br />");
			out.println("<input type=\"text\" name=\"adminPass\" /><br />");
			out.println("The password is: \"I am an admin\"");
		}
	%><br /><br />
	<input type="submit" id="submitProfile" class="regularButton" value="edit profile" /><br />
</p></form>
</body>
</html>